package com.lin.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import com.lin.utils.StringUtils;
import com.lin.vo.User;
@WebFilter(filterName="PrivilegeFilter",urlPatterns={"/jsps/order/*","/jsps/cart/*"})
public class PrivilegeFilter implements Filter{

	@Override
	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
			throws IOException, ServletException {
		
		/**
		 * 1.获取Session域中的用户登录信息
		 */
		HttpServletRequest request=(HttpServletRequest)servletRequest;
		User user = (User) request.getSession().getAttribute("exitUser");
		if(user == null){
				request.setAttribute("msg", "亲,您还没登陆捏~");
				request.getRequestDispatcher("/jsps/msg.jsp").forward(request, servletResponse);
				return;
		}else{
			filterChain.doFilter(request, servletResponse);
		}
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		
	}

}
